const ora = require('ora');
const download = require('download-git-repo')
const rm = require('rimraf').sync
const { promisify } = require('util')
const  chalk  = require('chalk')
const  promiseDownload = promisify(download)

module.exports.clone = async function (repo, desc) {
    const spinner = ora(chalk.magenta('正在下载:'+repo));
    spinner.start();

    try {
        rm(desc)
        await promiseDownload(repo,desc,{ clone: true })

    } catch (error) {
        spinner.fail(chalk.bold.red('下载失败'))
    }
    spinner.succeed(`${chalk.green('下载完成')}`)

}